Ext.define('channel.commodity.CommoditySnapSearchWin',{
	closeAction : 'hide',
	extend : 'Ext.window.Window',
	width : 500,
	resizable : false,
	modal : true,	
	initComponent : function(){
		this.form = Ext.create('Ext.form.Panel',{
			border : false,		
			bodyPadding: 5,
			defaults : {labelAlign : 'right',anchor:'90%',xtype:'textfield'},
			items :[
				{
			        fieldLabel: '商品编号',
			        name: 'commodity',
			        xtype : 'numberfield',
			        maxLenght : 50
			    },
			    {
					fieldLabel:'渠道',
	                xtype: 'radiogroup',
	                layout: 'column',
	                allowBlank: false,
	                defaults: {
	                    name: 'distribute',
	                    margins: '0 50 0 0'
	                },
	                items: [{
	                    inputValue: -1,
	                    boxLabel: '所有渠道',
	                    checked: true
	                }, {
	                    inputValue: 110,
	                    boxLabel: '淘宝商城 '
	                }, {
	                    inputValue: 123,
	                    boxLabel: '淘宝医学店 '
	                }, {
	                    inputValue: 122,
	                    boxLabel: '淘宝经管店 '
	                }, {
	                    inputValue: 111,
	                    boxLabel: '拍拍商城 '
	                }, {
	                    inputValue: 112,
	                    boxLabel: '新浪商城  '
	                }, {
	                    inputValue: 120,
	                    boxLabel: '我有商城 '
	                }]
	            },{
			        fieldLabel: '商品名称',
			        name: 'name',
			        maxLenght : 50
			    },
				{
			        fieldLabel: '渠道商品号',
			        name: 'distributeCommodity',
			        maxLenght : 50
			    },
				{
			        fieldLabel: '图片摘要',
			        name: 'coversdigest',
			        maxLenght : 50
			    }
			]
		});
		this.items = [this.form];
		this.buttons = [
			{text:'搜索',scope:this,handler:this._search},
			{text:'取消',scope:this,handler:function(){this.hide();}}
		];
		this.callParent();
		this.on('hide',function(){this.form.form.reset();},this);
		this.on('show',function(){	
			var o = this.fcmp;
			this.form.form.reset();
			this.form.form.findField('commodity').focus(true,true);
		},this);
	},
	_search : function(){
		if(this.form.form.isValid()){
			var dataIn = this.form.form.getValues();
			dataIn.url = '/commoditysnap/search.json';
			channel.openLink({
				url	:dataIn.url,
				params : dataIn,
				scope : this,
				masker : this,
				onSuccess : function(rs){
					this.hide();
					var records=new Array();
					var list = rs.result;
					for(var i=0;i<list.length;i++){
						var r = new CommoditySnap({
							name:list[i].name,
							createtime:list[i].createtime,
							onshelf:list[i].onshelf,
							distributeCommodity:list[i].distributeCommodity,
							price:list[i].price,
							stock:list[i].stock,
							coversdigest:list[i].coversdigest,
							descriptiondigest:list[i].descriptiondigest,
							lastupdatetime:list[i].lastupdatetime,
							'commoditySnapPK.commodity':list[i].commoditySnapPK.commodity,
							'commoditySnapPK.distribute':list[i].commoditySnapPK.distribute
							});
						records.push(r);
					}
					this.fcmp.center.store.removeAll();
					this.fcmp.center.store.add(records);
				}
			});
		}
	}
});